package com.netstar.property;

import java.io.IOException;

import org.json.JSONException;

public abstract class IntProperty extends PrimitiveProperty {
	public abstract void set(Property obj, int val);

	public abstract int get(Property obj);

	public IntProperty() {
	}

	@Override
	public void copy(Property lhs, Property rhs) {
		set(lhs, get(rhs));
	}

	@Override
	public void parse(Property obj, Object value) throws JSONException,
			IOException {
		if (value == null) {
			set(obj, 0);
		} else {
			if (value instanceof Integer) {
				set(obj, (Integer) value);
			} else {
				try {
					set(obj, Integer.parseInt(value.toString()));
				} catch (Exception e) {
					// TODO: handle exception
					throw new JSONException(
							"IntProperty ---the value must be munber value = "
									+ value);
				}
			}
		}
	}

}
